/**
 * copyright (c) 2017-2022 厦门风领科技有限公司
 * http://www.fenglinghudong.com/
 * 
 * 振动管理.
 * Zy.
 * 2023-10-24.
 */

import { GGStore } from "../../../framework/core/base/GGStore";

/** 振动强度类型. */
export enum EVibrate {
    heavy = "heavy",
    medium = "medium",
    light = "light",
}

/** 振动管理. */
export class VibrateManager {

    private static _enable: boolean = null;
    /** 开关. */
    public static set enable(v: boolean) {
        VibrateManager._enable = v;
        GGStore.set("VibrateEnable", v);
    }
    public static get enable(): boolean {
        if (VibrateManager._enable == null) {
            VibrateManager._enable = GGStore.get("VibrateEnable", true);
        }
        return VibrateManager._enable;
    }

    /** 短振动(15ms). */
    public static vibrateShort(type: EVibrate = EVibrate.medium) {
        return new Promise<any>((resolve, reject) => {
            if (gg.isH5) { return; }
            if (VibrateManager.enable && gg.vibrateShort) {
                gg.vibrateShort({
                    type: type,
                    success: (res) => { resolve(res); },
                    fail: (err) => {
                        console.log("vibrateShort fail -> err: ", err);
                        // reject(err);
                    }
                });
            }
        });
    }

    /** 长振动(400ms). */
    public static vibrateLong() {
        return new Promise<any>((resolve, reject) => {
            if (gg.isH5) { return; }
            if (VibrateManager.enable && gg.vibrateLong) {
                gg.vibrateLong({
                    success: (res) => { resolve(res); },
                    fail: (err) => {
                        console.log("vibrateLong fail -> err: ", err);
                        // reject(err);
                    }
                });
            }
        });
    }

}
